//
//  ViewController.swift
//  jnwweiyi
//
//  Created by robin shie on 15/2/5.
//  Copyright (c) 2015年 shie robin. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
       
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
        let redball = UIView(frame: CGRectMake(50, 50, 100, 100))
        redball.backgroundColor = UIColor.blueColor()
        //redball.layer.cornerRadius = 50
        self.view.addSubview(redball)
        let move = JNWSpringAnimation(keyPath: "transform.translation.x")
        move.damping = 6
        move.stiffness = 100
        move.mass = 2
        move.fromValue = 0
        move.toValue = 200
        redball.layer.addAnimation(move, forKey: move.keyPath)
        redball.transform = CGAffineTransformMakeTranslation(200, 0)
        //
        let scale = JNWSpringAnimation(keyPath: "transform.scale")
        scale.damping = 6
        scale.stiffness = 100
        scale.mass = 2
        scale.fromValue = 1
        scale.toValue = 2
        redball.layer.addAnimation(scale, forKey: scale.keyPath)
        redball.transform = CGAffineTransformMakeScale(2, 2)
        //
        let rotation = JNWSpringAnimation(keyPath: "transform.rotation")
        rotation.damping = 6
        rotation.stiffness = 100
        rotation.mass = 2
        rotation.fromValue = 0
        rotation.toValue = M_PI_2
        redball.layer.addAnimation(rotation, forKey: rotation.keyPath)
        redball.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
    }

}

